package com.xxpt.common.utils.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * biz_train_record_info表中的分发状态转换: 1-未分发,2-已分发
 *
 * @author icetea
 */
public class PublishStatusConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * excel单元格转javabean方法
     */
    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return "已分发".equals(cellData.getStringValue()) ? 2 : 1;
    }

    /**
     * javaBean转excel单元格方法
     */
    @Override
    public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return value.intValue() == 2 ? new CellData(CellDataTypeEnum.STRING, "已分发") : new CellData(CellDataTypeEnum.STRING, "未分发");

    }

}
